package org.ourgrid.broker.business.schedulerdata.executor;

import java.util.ArrayList;
import java.util.List;

import org.ourgrid.broker.business.schedulerdata.SchedulerData;
import org.ourgrid.common.internal.IResponseTO;
import org.ourgrid.common.internal.response.LoggerResponseTO;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class LoggerExecutor extends AbstractSchedulerDataExecutor {
	
	/**
	 * <LOGGER message='String' type='int'/>
	 */
	public List<IResponseTO> execute(SchedulerData command) {
		List<IResponseTO> responses = new ArrayList<IResponseTO>();
		
		Document logDocFile = super.getXMl(command.getXml());
		
		Element element = logDocFile.getDocumentElement();
		
		String message = element.getAttribute("message");
		int type = Integer.valueOf(element.getAttribute("type"));
		
		LoggerResponseTO to = new LoggerResponseTO();
		to.setMessage(message);
		to.setType(type);
		
		responses.add(to);
		
		return responses;
	}
}
